﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FlyBehavior : IAnimationInit
{
    private Rigidbody rig;
    public float upG ;//向上抵消的加速度
    public float drag ;//空气阻力
    public Rigidbody Rig
    {
        set
        {
            rig = value;
        }
    }
    public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        //Debug.Log("state enter "+stateInfo.nameHash);
        if (rig == null) rig = animator.transform.parent.GetComponent<Rigidbody>();
        if (rig == null) Debug.LogError("FlyBehavior can't find rig");
    }
    public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        rig.drag = drag;
        rig.AddForce(Vector3.up * upG * rig.mass);//增加上升力
    }
    public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        //Debug.Log("exit"+stateInfo.nameHash);
        rig.drag = 0;
    }
  
}
